import requests
import app
import json

# add_employee_data = {
#     "username":"yx1115",
#     "mobile":"16634544112",
#     "timeOfEntry":"2020-07-09",
#     "formOfEmployment":1,
#     "workNumber":"11041086",
#     "departmentName":"销售",
#     "departmentId":"1266699057968001024",
#     "correctionTime":"2020-07-30T16:00:00.000Z"
#         }


class EmployeeAPI:
    def __init__(self):
        self.url_add_employee = app.BASE_URL+app.ADD_URL
        self.url_update_employee = app.BASE_URL+app.ADD_URL+"/{}"
        self.url_get_employee = app.BASE_URL+app.ADD_URL+"/{}"
        self.url_delete_employee = app.BASE_URL+app.ADD_URL+"/{}"

        print(self.url_add_employee)

    def add_employee(self,add_employee_data):

        print(add_employee_data)
        print(app.headers_data)
        # reponse = requests.post(url=self.url_add_employee, json=add_employee_data, headers=app.headers_data)
        reponse=requests.post(url=self.url_add_employee, json=add_employee_data, headers=app.headers_data)
        print(reponse.json())
        return reponse

    def update_employee(self,employee_id,update_employee_data):
        print(employee_id)
        print(update_employee_data)
        url = self.url_update_employee.format(employee_id)
        print(url)
        return requests.put(url=url,json=update_employee_data,headers = app.headers_data)
        pass
    def get_employee(self,employee_id):
        url = self.url_get_employee.format(employee_id)
        print(url)
        response = requests.get(url=url, headers=app.headers_data)
        print(response.json())
        return response
    def delete_employee(self,employee_id):
        url = self.url_delete_employee.format(employee_id)
        return requests.delete(url=url,headers = app.headers_data)

# ap= EmployeeAPI()
# # re=ap.add_employee(add_employee_data)
# ap.get_employee()
# ap.add_employee(add_employee_data)
# print()